package com.hoshino.momochi.util;

import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;

public enum CodeEnum {
    CODESEND("验证码已经发送", 1),
    SENDFAIL("发送失败", 0),
    USERID("USER_ID", 0),
    TOKEN("HOSHINO_T_KK", 0),
    MAILEXIST("邮箱已经被使用过了", 0),
    MAILNULL("邮箱不能为空", 0),
    USERNAMEEXIST("用户名已经存在", 0),
    LOGINNULL("用户名或密码不能为空", 0),
    CODENULL("验证码不能为空", 0),
    CODEFAIL("验证码错误", 0),
    REGISTER("注册成功", 1),
    REVOKE("注销成功", 1),
    LOGINOUT("退出登录", 1),
    NOTNULL("不能有输入空值", 0),
    ERROR("错误", 0),
    SUCCESS("成功", 1),
    USERREVOKE("用户已经注销", 0),
    COLLECTIONNOTEXIST("收藏夹不存在", 0),
    ISEXIST("已经存在", 0),
    NOTOWN("不能操作自己", 0),
    NOTPERMISS("没有权限", 0),
    NOTEXIST("不存在", 1),
    BLOGID("BLOG_ID", 0),
    LIKEEXIST("已经点过赞了", 0),
    LIKENEXIST("没有点过赞", 0),
    BLOGPREFIX("cache_blog_page", 0),
    BLOGINFO("", 10),

    ;

    private final String message;

    private final Integer code;

    CodeEnum(String message, Integer code) {
        this.message = message;
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public Integer getCode() {
        return code;
    }

    // 以下备用
    private static Map<String, CodeEnum> NAME_MAP = Arrays.stream(CodeEnum.values()).collect(Collectors.toMap(CodeEnum::name, s -> s));

    public static CodeEnum getByName(String typeCode) {
        return NAME_MAP.get(typeCode);
    }
}
